﻿using Dapper;
using Entity;
using IRealize;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Realize
{
    public class SS:ISS
    {
        public async Task<int> Delete(int id, string sqlserver)
        {
            using (SqlConnection con = new SqlConnection(sqlserver))
            {
                string sql = $"delete from salary_standard where sdt_id = ${id}";
                return await con.ExecuteAsync(sql);

            }
        }

        public async Task<int> Insert(string Dig, string XC_name, double ZE, string ZDR, string DJR, DateTime DJSJ, string BZ, string sqlserver)
        {

            using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
            {
                string sql = $@"insert into salary_standard(standard_id,standard_name,designer,register,regist_time,salary_sum,remark)
                 values('{Dig}','{XC_name}','{ZDR}','{DJR}','{DJSJ}',{ZE},'{BZ}')";
                return await sqlConnection.ExecuteAsync(sql);
            }
        }

        public async Task<List<Salary_Standard>> Server(string sqlserver)
        {
            Task<List<Salary_Standard>> task = Task<List<Salary_Standard>>.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {

                    string sql = $"select * from salary_standard where check_status = 0 and change_status = 0";
                    return con.Query<Salary_Standard>(sql).ToList();
                }
            });
            return await task;
        }
        public async Task<List<Salary_Standard>> Server3(string sqlserver)
        {
            Task<List<Salary_Standard>> task = Task<List<Salary_Standard>>.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {

                    string sql = $"select * from salary_standard";
                    return con.Query<Salary_Standard>(sql).ToList();
                }
            });
            return await task;
        }
        public async Task<List<Salary_Standard>> Server2(string s_id, string sqlserver)
        {
            Task<List<Salary_Standard>> task = Task<List<Salary_Standard>>.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {

                    string sql = $"select * from salary_standard where standard_id = '{s_id}'";
                    return con.Query<Salary_Standard>(sql).ToList();
                }
            });
            return await task;
        }

        public async Task<int> Update(string Dig, string XC_name, double ZE, string ZDR, string DJR, DateTime DJSJ, string BZ, string sqlserver)
        {
            using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
            {
                string sql = $@"update salary_standard set standard_name = '{XC_name}',designer = '{ZDR}',register = '{DJR}',check_time = '{DJSJ}',salary_sum = {ZE},check_comment = '{BZ}',change_status = 1
                  where standard_id = '{Dig}'";
                return await sqlConnection.ExecuteAsync(sql);
            }
        }
        public async Task<int> Update2(string Dig, string XC_name, double ZE, string ZDR, string DJR, DateTime DJSJ, string BZ, string sqlserver)
        {
            using (SqlConnection sqlConnection = new SqlConnection(sqlserver))
            {
                string sql = $@"update salary_standard set standard_name = '{XC_name}',designer = '{ZDR}',register = '{DJR}',check_time = '{DJSJ}',salary_sum = {ZE},check_comment = '{BZ}',change_status = 1
                  where standard_id = '{Dig}'";
                return await sqlConnection.ExecuteAsync(sql);
            }
        }
    }
}
